import {AsyncStorage} from 'react-native';

let UserUtils = {
    async loadUserInfo() {
        try {
            return JSON.parse(await AsyncStorage.getItem("UserInfo"));
        } catch (e) {
            return null;
        }
    },

    saveUserInfo(user) {
        this.loadUserInfo().then((userInfo) => {
            if (userInfo) {
                AsyncStorage.mergeItem("UserInfo", JSON.stringify(user))
            } else {
                AsyncStorage.setItem("UserInfo", JSON.stringify(user))
            }
        })
    }
}
export default UserUtils;